package com.wc.算法基础课.A第一讲基础算法.递归.正则问题;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/3/13 10:12
 * @description https://www.acwing.com/problem/content/1227/
 */
public class Main {
    static int k = 0;
    static char[] s = new char[1];
    static int n;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        s = sc.next().toCharArray();
        n = s.length;
        System.out.println(dfs());
    }

    static int dfs() {
        int res = 0;
        while (k < n) {
            if (s[k] == '(') {
                // 把左括号跳过去
                k++;
                res += dfs();
                // 把右括号跳过去
                k++;
            } else if (s[k] == '|') {
                // 把这个或跳过去
                k++;
                res = Math.max(res, dfs());
            } else if (s[k] == ')') break;
            else {
                k++;
                res++;
            }
        }


        return res;
    }
}
